<?php
namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Exception;
use think\Facade\Env;

/**
 * Class Profit
 * @package app\command
 */
class ResetCard extends Command
{
    protected $contractHelper = null;
    protected  $mtHelper =null;
    protected function configure()
    {
           $this->setName('ResetCard')
               ->setDescription('退卡');
    }


    protected function execute(Input $input, Output $output){

        $end = time()-10*60;
        $rows = Db::table("tb_order")->where("status",-1)->where("deal",0)->where("create_time","<",$end)->order("id asc")->select();
        foreach ($rows as $index=>$row){
            if ($row["card"]){
               try{
                   Db::table("tb_card_info")->where("card",$row["card"])->update(["status"=>0]);
                   Db::table("tb_order")->where("id",$row["id"])->update(["deal"=>1]);
               }catch (\Exception $e){
                   echo  $e->getMessage()."\n";
               }
            }
        }

    }



}
